package com.study.controller;

import com.study.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/t1")
    public String test(@RequestParam("username") String name, Model model){
        //1.接收前端参数
        System.out.println("接收到前端参数为："+name);

        //2.将返回的结果传递给前端 model
        model.addAttribute("msg",name);

        //3.跳转视图
        return "hello";
    }


    //如果传递的是一个对象User，匹配User对象中的字段名：如果名字一致则OK，否则匹配不到
    @RequestMapping("/t2")
    public String test(User user, Model model){

        System.out.println("接收到前端参数为："+user);

        model.addAttribute("msg","接收到前端参数为："+user);

        return "hello";
    }


}
